{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "计算"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "50\n"
     ]
    }
   ],
   "source": [
    "sum = 0\n",
    "for i in range(1,100,1):\n",
    "    if i%2 != 0:\n",
    "        sum += i\n",
    "    else:\n",
    "        sum -= i\n",
    "print(sum)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-23T19:52:12.832053Z",
     "end_time": "2024-10-23T19:52:12.837571Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "输入字符并统计"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "该字符串中数字的个数是： 5\n",
      "该字符串中字母的个数是： 5\n",
      "该字符串中空格的个数是： 6\n",
      "该字符串中其他字符的个数是： 5\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "letter = 0\n",
    "number = 0\n",
    "space = 0\n",
    "others = 0\n",
    "str = 'asdfg   12345   %$#@!'\n",
    "number += len(re.findall(r'[0-9]',str))\n",
    "print(f\"该字符串中数字的个数是：\",number)\n",
    "letter += len(re.findall(r'[a-zA-Z]',str))\n",
    "print(f\"该字符串中字母的个数是：\",letter)\n",
    "space += len(re.findall(r'[ ]',str))\n",
    "print(f\"该字符串中空格的个数是：\",space)\n",
    "others += len(re.findall(r'[^0-9a-zA-Z ]',str))\n",
    "print(f\"该字符串中其他字符的个数是：\",others)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-10-24T17:37:38.222903Z",
     "end_time": "2024-10-24T17:37:38.233180Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
